package edu.guet.server.controller;

import edu.guet.server.model.Comment;
import edu.guet.server.model.Semester;
import edu.guet.server.model.dto.ExcellentCourseDTO;
import edu.guet.server.model.vo.ExcellentCourseVO;
import edu.guet.server.service.CommentService;
import edu.guet.server.service.CourseService;
import edu.guet.server.service.ExcellentCourseService;
import edu.guet.server.service.SemesterService;
import edu.guet.server.utils.ResultAPI;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.*;


import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping
public class ExcellentCourseController {
    @Autowired
    private ExcellentCourseService excellentCourseService;
    @Autowired
    private SemesterService semesterService;
    @Autowired
    private CourseService courseService;
    @Autowired
    CommentService commentService;
//    /**
//     * 显示精品课程
//     * @param excellentCourseDTO
//     * @return
//     */
//    @PostMapping("/semester/showjingpin")
//    public ResultAPI showCourses(@RequestBody(required = false) ExcellentCourseDTO excellentCourseDTO){
//        System.out.println("DTO:"+excellentCourseDTO.getCourse_id());
//        List<ExcellentCourseVO> courseVO;
//        //如果没传参数则默认按时间降序
//        //这个降序还有点问题，直接传id是可以的
//        if(excellentCourseDTO == null){
//            courseVO = excellentCourseService.findCourseOrderByTime();
//            if(courseVO == null){
//                return ResultAPI.error("数据库中没有相关信息...");
//            }
//        }else{
//            //有参数则按照id查
//            if(excellentCourseService.checkIdsExist(excellentCourseDTO)){
//                //判断id是否存在
//                courseVO = excellentCourseService.showCourses(excellentCourseDTO);
//            }else {
//                return ResultAPI.error("id不存在");
//            }
//        }
//        log.info("courseVO:"+courseVO);
//        return ResultAPI.success(courseVO);
//    }
    @GetMapping("/semester/showjingpin")
    public ResultAPI showJingpin(@RequestParam Integer course_id) {
        log.info("轮播: {}", course_id);
        List<ExcellentCourseVO> list=semesterService.findSemesterByCourseId(course_id);
        return ResultAPI.success(list);
    }
    @GetMapping("/comment/excellent")//精彩评论
    public ResultAPI selectCommentExcellent(@RequestParam int course_id) {
        List<Comment> list=commentService.getMostComment(course_id);
        return ResultAPI.success(list);
    }
}
